/*O5D+1x4SNFIcB+n3WzGo6ASAeLnsNPmk2FmP0LTwWoyVC0kDNZ0P5fpSWz17HeK8*/
import {
	contractTransferPageCode,
	contractAppcode,
	contractTransferHead,
	contractTransferSearch,
	ContractReferFilterConfig
} from '../constants';
import ampub from 'ampub';
import fa from 'fa';
const { fa_components: { ReferFilter: { addSearchAreaReferFilter }, CardLinkToBillUtil: { CardLinkToBill } } } = fa;
const {
	components: {
		RefFilterForSearchArea: { refCommonFilterForSearchArea, appPermissionOrgRefFilter, commonRefFilter },
        refInit: { defRefCondition, commonRefCondition },
		AMTooltip
	},
	utils
} = ampub;
const { msgUtils: { showMessage }, multiLangUtils: { getMultiLangByID } } = utils;

export default function(props) {
	let that = this;
	props.createUIDom(
		{
			pagecode: contractTransferPageCode,
			appcode: contractAppcode
		},
		function(data) {
			if (data) {
				if (data.template) {
					let meta = data.template;
					meta = modifierMeta.call(this, props, meta);
					props.meta.addMeta(meta);
					that.updateDataFn();
				}
			}
		}
	);
}
function modifierMeta(props, meta) {
	// 查询条件过滤
	addSearchAreaReferFilter.call(this, props, meta, ContractReferFilterConfig);

    let filterByPkOrg = [
        'pk_redept_in',
        'pk_redept_out',
        'pk_recorder_in',
        'pk_supplier',
        'pk_customer',
        'pk_payment'
    ];
	//查询区的参照处理
	meta[contractTransferSearch].items.map((item) => {
		if (filterByPkOrg.includes(item.attrcode)) {
			// 根据资产组织过滤
			commonRefFilter.call(this, props, item, contractTransferSearch, filterByPkOrg, 'pk_org');
		}else if('pk_fiorg_in' == item.attrcode){
            /* 财务组织过滤 */
            appPermissionOrgRefFilter(item);
        }
	});

	//增加超链接
	meta[contractTransferHead].items = meta[contractTransferHead].items.map((item, key) => {
		//合同号添加下划线超链接
		if (item.attrcode == 'contract_no') {
			item.render = (text, record, index) => {
				return (
					<div className="simple-table-td">
						<AMTooltip>
							<span
								className="code-detail-link"
								onClick={() => {
									billreview(props, record);
								}}
							>
								{record.contract_no && record.contract_no.value}
							</span>
						</AMTooltip>
					</div>
				);
			};
		}
		return item;
	});

	return meta;
}

//单据追溯
function billreview(props, record) {
	//获取卡片来源 4A3A
	//获取来源主键
	let pk_bill_src = record.pk_contract.value;
	let transi_type = record.transi_type.value;

	if (pk_bill_src) {
		CardLinkToBill.call(this, props, pk_bill_src, transi_type);
	} else {
		/*国际化处理：该单据的来源单据号错误*/
		showMessage(props, { content: getMultiLangByID('201201504A-000021'), color: 'warning' });
	}
}

/*O5D+1x4SNFIcB+n3WzGo6ASAeLnsNPmk2FmP0LTwWoyVC0kDNZ0P5fpSWz17HeK8*/